<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <title>房源信息</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <style type="text/css">
        .layui-table-cell {
            height: 100%;
            max-width: 100%;
        }
    </style>
</head>
<body>

<form class="layui-form">

    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" id="value" style="width: 330px" name="name" lay-verify="required" placeholder="请输入小区名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <button type="button" class="layui-btn" id="search">搜索</button>
</form>

<table id="roomTable" lay-filter="roomTable"></table>

<!-- 编辑页面开始 -->
<form class="layui-form" id="amendRoomForm" lay-filter="amendRoomForm" style="display: none;padding: 20px 55px 0px 0px">
    <input type="hidden" id="id" name="id" value="">
    <div class="layui-form-item">
        <label class="layui-form-label">位置属性</label>
        <div class="layui-input-block">
            <input type="text" name="address" placeholder="请输入房源位置属性" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">房源小区</label>
        <div class="layui-input-block">
            <input type="text" name="resource" placeholder="请输入房源小区" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">房源面积</label>
        <div class="layui-input-block">
            <input type="text" name="houseArea" placeholder="请输入房源面积" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">计租面积</label>
        <div class="layui-input-block">
            <input type="text" name="rentalArea" placeholder="请输入计租面积" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">户型</label>
        <div class="layui-input-block">
            <input type="text" name="houseType" placeholder="请输入房源户型信息" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">建筑结构</label>
        <div class="layui-input-block">
            <input type="text" name="structure" placeholder="请输入房源建筑结构" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">租赁性质</label>
        <div class="layui-input-block">
            <input type="text" name="nature" placeholder="请输入房源租赁性质" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">房源状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="0" title="建成待租">
            <input type="radio" name="status" value="1" title="未建成">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit  lay-filter="amendRoomSubmit">确认修改</button>
            <button type="button"  id="closeAmendRoom" class="layui-btn layui-btn-primary">关闭</button>
        </div>
    </div>
</form>
<!-- 编辑页面结束 -->



<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">


    layui.use(['table','form','layer'], function () {

        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        table.render({
            elem:'#roomTable'
            ,url:'house-room-resource/list'
            ,page:true
            ,limit:10
            ,limits:[6,8,10,20]
            ,cols:[[
                {field:'roomId',title:'编号',sort:true,width:80,align:'center'}
                ,{field:'roomName',title:'房源名称',align:'center'}
                ,{field:'address',title:'位置属性',align:'center'}
                ,{field:'resource',title:'房源小区',align:'center'}
                ,{field:'houseArea',title:'房源面积',align:'center'}
                ,{field:'rentalArea',title:'计租面积',align:'center'}
                ,{field:'houseType',title:'户型',align:'center'}
                ,{field:'structure',title:'建筑结构',align:'center'}
                ,{field:'nature',title:'租赁性质',align:'center'}
                ,{field:'status',title:'小区',align:'center',templet:function (d) {
                        if (d.status == 0) {
                            return "建成待租";
                        }else {
                            return "未建成";
                        }
                    }}
                ,{toolbar: '#barDemo', align:'center'}
            ]]
        });
        /**
         * 监听roomTable的查看编辑删除按钮的单击事件
         * */
        table.on('tool(roomTable)',function (obj) {
            var data = obj.data;
            //编辑按钮的单击事件
            if(obj.event=='edit'){
                form.val("amendRoomForm",data);
                layer.open({
                    type:1,
                    title:['编辑房源信息','font-size:18px;color:orange;'],
                    area:['760px','80%'],
                    content:$("#amendRoomForm"),
                });
            }
        });

        /**
         * 监听修改页面的确认修改按钮
         * */
        form.on("submit(amendRoomSubmit)",function (obj) {
            layer.confirm("你确定要修改房源信息吗？",{icon:'3',title:'提示'},function () {
                $.ajax({
                    url:'house-room-resource/update',
                    data:obj.field,
                    type:"put",
                    dataType:"json",
                    success:function (data) {
                        if(data.code==200){
                            obj.form.reset();
                            layer.closeAll();
                            table.reload("roomTable");
                            layer.msg("修改房源信息成功！",{icon:'1',title:'提示',closeBtn :'1'});
                        }
                    }
                });
            })
            return false;
        });
        /**
         * 各个页面的一些关闭按钮
         * */
        $("#closeAmendRoom").click(function () {
            layer.closeAll();
        })
        /**
         * 搜索功能
         * */
        $("#search").click(function () {
            if($("#value").val()==""){
                table.reload("roomTable",{
                    url:'house-room-resource/list',
                    page:{
                        curr:1
                    }
                });
            }else{
                table.reload("roomTable",{
                    url:'house-room-resource/search',
                    where:{
                        name:$("#value").val()
                    }
                });
            }
        });

    });
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>

</body>
</html>